//https://leetcode.cn/problems/reverse-words-in-a-string-iii/
//反转字符串中的单词
//给定一个字符串 s ，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。

class Solution {
public:
    string reverseWords(string s) {
        string::iterator pos = s.begin(), pre = s.begin();
        while(pos != s.end())
        {
            if(*pos == ' ')
            {
                reverse(pre, pos);
                pre = pos + 1;
            }
            pos++;
        }
        reverse(pre, pos);

        return s;
    }
};